<?php

include_once("db/UserDAO.inc");
include_once("db/AccessLevel.inc");
include_once("db/Ministry.inc");
include_once("db/Department.inc");
include_once("db/Province.inc");

/*
 * Generates a drop-down list of all available Access Levels.
 * IMPORTANT: some of the decisions made here are hard-coded, and are
 * extremely dependent on database values!
 * 
 * $currentLevel - The current user's level.  If the user is an admin, then
 * they can set any value here.  If they are a supervisor, then they
 * can only view the remaining three.
 */
function showAccessLevelList($currentLevel, $default) {
	$levels = AccessLevel::getAllAccessLevels();
	
	print "<select name=\"accessLevel\">";
	foreach ($levels as $l) {
		if ($currentLevel == 1 ||
			($currentLevel == 4) && ($l->id == 2 || $l->id == 3 || $l->id == 5)) {
				print "<option value=\"$l->id\"";
				if ($default == $l->id) print "selected=\"selected\"";
				print ">$l->id - $l->description</option>";
		}
	}
	print "</select>";
}

/*
 * Generates a drop-down list of all available ministries.
 */
function showMinistryDropDown($def) {
	$m = Ministry::getAllMinistries();
	
	print "<select name=\"ministry\">";
	foreach ($m as $min) {
		print "<option value=\"$min->id\"";
		if ($def == $min->id) print " selected=\"selected\"";
		print ">$min->id - $min->description</option>"; 	
	}
	print "</select>";
}

/*
 * Generates a drop-down list of all available departments.
 */
function showDepartmentDropDown($def) {
	$deps = Department::getAllDepartments();
	
	print "<select name=\"department\">";
	foreach ($deps as $d) {
		print "<option value=\"$d->id\"";
		if ($def == $d->id) print " selected=\"selected\"";
		print ">$d->id - $d->description</option>";
	}
	print "</select>";	
}

/*
 * Generates a drop-down list of all available provinces.
 */
function showProvinceDropDown($def) {
	$provs = Province::getAllProvinces();
	
	print "<select name=\"province\">";
	foreach ($provs as $p) {
		print "<option value=\"$p->id\"";
		if ($def == $p->id) print " selected=\"selected\"";		
		print ">$p->id - $p->name</option>";
	}	
	print "</select>";
}

/*
 * Generates a drop-down list of all districts for the specified province,
 * selecting the default value.
 */
function showDistrictDropDown($provId, $def) {
	$dists = District::getAllDistricts($provId);
	
	print "<select id=\"district\" name=\"district\">";
	foreach ($dists as $d) {
		print "<option value=\"$d->id\"";
		if ($def == $d->id) print " selected=\"selected\"";
		print ">$d->id - $d->name</option>";
	}
	print "</select>";
}

?>